package com.nxj.servlet;

import com.nxj.factory.IOCAnnotationFactory;
import com.nxj.service.TransferService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "transferServlet", urlPatterns = "/transferServlet")
public class MainServlet extends HttpServlet {

    TransferService transferServiceImpl = (TransferService) IOCAnnotationFactory.getBean("transferServiceImpl");

    //ProxyFactory proxyFactory = (ProxyFactory) IOCFactory.getBean("proxyFactory");
    //TransferService transferService = (TransferService) proxyFactory.jdkProxy(proxyFactory);

    public MainServlet() {
        System.out.println("new MainServlet!!!");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String fromNo = req.getParameter("fromCardNo");
        String toNo = req.getParameter("toCardNo");
        String money = req.getParameter("money");
        try {
            transferServiceImpl.trans(fromNo, toNo, money);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
